﻿using System.Windows;
using System.Windows.Input;
using IMClient.ViewModels;
using IMClient.WebSocketService;

namespace IMClient.View
{
    /// <summary>
    /// ChatWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ChatWindow : Window
    {
        public ChatWindow()
        {
            InitializeComponent();
            DataContext = ChatWindowViewModel.Instance;
        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState == MouseButtonState.Pressed)
            {
                DragMove(); // 拖动窗口
            }
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
            // 关闭 WebSocket 连接
            if (WebSocketConnection.WS != null)
            {
                await WebSocketConnection.WS.CloseAsync(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "Window closing", CancellationToken.None);
            }
        }
    }
}
